<template>
	<view class="main" :style="{paddingBottom:(getSafeBottom + bottomBtnHeight)+'px'}">
		<navbar title="求职意向"></navbar>
		<view class="item-box" :style="{paddingTop:(getStateHeight + getNavbar  ) + 'px'}" v-if="dataList.length>0">

			<delSlideLeft :item="item" :data_transit="{index:index,item:item}" @delItem="delItem" v-for="item in dataList" @leftMove="leftMove">
				<view class="item" :key="item.id" @click="toDetail(item)">
					<view class="item-line">
						<view class="item-title">
							{{item.gangwei}}
						</view>
					</view>
					<view class="item-line">
						<text>{{item.gangwei}}</text>
						<text>{{item.workType=="不限"?"工作形式不限":item.workType}}</text>
						<text>{{item.isMian==1?"面议":(Math.floor(item.workSalary)+(item.workDanwei?item.workDanwei:"元/天"))}}</text>
					</view>
					<view class="item-date">
						创建日期：{{item.timeCreate.split(' ')[0]}}
					</view>
				</view>

			</delSlideLeft>

		</view>
		<empty v-else></empty>
		<view class="main-button" :style="{paddingBottom:getSafeBottom+'px'}" @click="addHandler()">
			<view class="main-button-add">
				新增求职意向
			</view>
		</view>
		<view class="main-bj">

		</view>
	</view>
</template>

<script>
	import {
		mapGetters
	} from 'vuex';
	import delSlideLeft from '@/components/ay-operate/del_slideLeft.vue'

	import Navbar from '@/components/Navbar.vue';
	import {
		postListToMy,
		removeSeeker
	} from "@/core/web-api/qiuzhiduan.js"
	import Empty from "@/components/Empty.vue"
	export default {
		components: {
			Navbar,
			Empty,
			delSlideLeft
		},
		data() {
			return {
				dataList: [],
				bottomBtnHeight: uni.upx2px(90),
				page: {
					current: 1,
					limit: 10
				},
				filters: {
					keywords: "",
					status: ""
				},
				total: 0,
				move:{},
			}
		},
		methods: {
			leftMove(e){
				if(e.id==this.move.id) return;
				this.move = e;
				this.dataList.forEach(item=>{
					if(e.id!=item.id){
						item.txtStyle = "left:0";
					}
				})
				let index = this.dataList.findIndex(f=>f.id==e.id)
				this.dataList[index].txtStyle = e.txtStyle
			},
			
			delItem({item}){
				removeSeeker({id:item.id}).then(res=>{
					if(res.code==20000){
						this.page.current = 1;
						this.getDataList();
					}
				})
			},
			toDetail(item) {
				uni.navigateTo({
					url: "/pages/ucenter/qiuzhiduan/qiuzhi/applyDetail?id=" + item.id
				})
			},
			addHandler() {
				uni.navigateTo({
					url: "/pages/ucenter/qiuzhiduan/qiuzhi/add"
				})
			},


			/**
			 * 加载数据
			 */
			getDataList() {
				postListToMy({
					...this.page,
					...this.filters
				}).then(res => {
					if (res.code == 20000) {
						const list = res.data.list;
						list.forEach(item=>{
							item.txtStyle = "left:0"
						})
						if (this.page.current == 1) {
							this.dataList = list;
						} else {
							this.dataList.push(...list)
						}
						this.total = res.data.total
					}
				})
			},

			// 分页
			pageData() {
				if (this.total == this.dataList.length) return;
				this.page.current++;
				this.getDataList();
			},
		},
		onReachBottom() {
			this.pageData();
		},
		onShow() {
			this.page.current = 1;
			this.getDataList();
		},
		computed: {
			...mapGetters(['getNavbar', 'getStateHeight', 'getSafeBottom']),
			getStatusClass() {
				return function(status, type) {
					let dist = {
						1: {
							className: "publish",
							name: "已发布"
						},
						2: {
							className: "audio",
							name: "审核中"
						},
						3: {
							className: "",
							name: "已关闭"
						}
					};
					return type == "className" ? dist[status].className : dist[status].name
				}
			}
		}
	}
</script>

<style scoped lang="less">
	.main {
		width: 100%;
		padding: 0 30upx;
		box-sizing: border-box;

		&-bj {
			width: 100%;
			height: 50vh;
			position: fixed;
			left: 0;
			top: 0;
			z-index: -1;
			background: linear-gradient(to bottom, #bdccfb, #f5f5f5);
		}

		&-button {
			width: 100%;
			position: fixed;
			background-color: #f5f5f5;
			left: 0;
			bottom: 0;
			padding-top: 10upx;
			z-index: 20;

			&-add {
				width: 690upx;
				height: 80upx;
				text-align: center;
				line-height: 80upx;
				border-radius: 10upx;
				background: linear-gradient(to bottom, #5472fd, #6ca5fd);
				font-size: 30upx;
				color: #ffffff;
				margin-left: 30upx;
				box-sizing: border-box;
			}
		}
	}

	.item {
		&-box {
			width: 100%;
			margin-top: 30upx;
			position: static;
			z-index: 2;
		}

		width: 100%;
		border-radius: 8upx;
		background-color: #fff;
		padding:25upx 30upx 30upx 30upx;
		box-sizing: border-box;
		box-shadow: 3upx 0 7upx rgba(220, 220, 220, .35);

		&-line {
			display: flex;
			align-items: center;
			margin-bottom: 15upx;

			&:last-child {
				margin-bottom: 0;
			}

			text {
				font-size: 26upx;
				color: #666666;
				display: block;
				height: 26upx;
				line-height: 26upx;
				padding-left: 10upx;
				margin-left: 10upx;
				border-left: 2upx solid #666;

				&:first-child {
					border-left: 0;
					padding-left: 0;
					margin-left: 0;
				}
			}
		}

		&-title {
			flex: 1;
			font-size: 34upx;
			color: #000;
			font-weight: bold;
			white-space: nowrap;
			/* 不换行 */
			overflow: hidden;
			/* 隐藏超出部分 */
			text-overflow: ellipsis;
			/* 使用省略号表示超出部分 */
		}

		&-price {
			font-size: 30upx;
			color: #0180ff;
		}

		&-date {
			font-size: 20upx;
			color: #999999;
			margin-top: 20upx;
		}
	}
</style>